package pictogram.front;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;


public class LeftFragment extends ListFragment {
	
	private EffectAdapter adapter;
	private OnItemSelectedListener listener;
	
	public void onCreate(Bundle savedInstanceState)
	{
				
		EffectList effect_data[] = new EffectList[]
		{
				new EffectList(R.drawable.i41),
				new EffectList(R.drawable.i42),
				new EffectList(R.drawable.i43),
				new EffectList(R.drawable.i44),
				new EffectList(R.drawable.i45),
				new EffectList(R.drawable.i46),
				new EffectList(R.drawable.i47),
				new EffectList(R.drawable.i48),
				new EffectList(R.drawable.i49),
				new EffectList(R.drawable.i410),
				new EffectList(R.drawable.i411),
				new EffectList(R.drawable.i412),
				new EffectList(R.drawable.i413),
		};
		
		adapter = new EffectAdapter(getActivity(), R.layout.listview_item_row, effect_data);
		setListAdapter(adapter);
				
		super.onCreate(savedInstanceState);
	}
	
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
	{
		View view = inflater.inflate(R.layout.left_fragment, container, false);
		
		return view;	
	}
	
	@Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        //Log.i(TAG, "[onListItemClick] Selected Position "+ position);
        itemSelected(position);
    }
	
	public void itemSelected(int effectSelected)
	{
		listener.onMainItemSelected(effectSelected);		
	}
	
	public interface OnItemSelectedListener
	{
		public void onMainItemSelected(int option);
	}
	
	public void onAttach(Activity activity) {
	      super.onAttach(activity);
	      if (activity instanceof OnItemSelectedListener) {
	        listener = (OnItemSelectedListener) activity;
	      } else {
	        throw new ClassCastException(activity.toString()
	            + " must implemenet MyListFragment.OnItemSelectedListener");
	      }
	    }

}

